package fictional.GUI;

import java.io.IOException;

import org.jdesktop.application.Application;

import fictional.Common.CharacterItem;
import fictional.Common.IBL;
import fictional.Common.Response;
import fictional.Common.ShortCharacterItem;

/**
 * This task changes the currently displayed character in the main
 * window. 
 */
public class ChangeDisplayedCharacterTask extends DefaultTask
{
	private ShortCharacterItem character;
	
	public ChangeDisplayedCharacterTask(Application application)
	{
		super(application);
	}

	public void setTask(IBL BL, GUI gui, ShortCharacterItem character)
	{
		this.BL = BL;
		this.gui = gui;
		this.character = character;
	}
	
    @Override
    protected Object doInBackground() throws IOException, InterruptedException
    {
    	response = new Response();
    	CharacterItem newCharacter = BL.getCharacter(character, response);
    	
    	if (response.isIs_Success())
    	{
        	gui.changeCurrentlyDisplayedCharacter(newCharacter);
    	}
    	else
    	{
    		errorTitle = "Error Changing Character View";
    	}
    	return null;
    }
}
